package org.zzm.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;

public class HibernateUtils {

	private static final String CONFIG_FILE = "hibernate.cfg.xml";

	private static SessionFactory sessionFactory;

	private static Configuration configuration;

	static {
		configuration = new AnnotationConfiguration().configure(CONFIG_FILE);
		sessionFactory = configuration.buildSessionFactory();
	}

	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public static Configuration getConfiguration() {
		return configuration;
	}

	public static Session openSession() {
		return sessionFactory.openSession();
	}

	public static Session getCurrentSession() {
		Session session = sessionFactory.getCurrentSession();
		return session;
	}

	public static void main(String [] args) {
		getCurrentSession();
	}
}
